#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int longestSemiRepetitiveSubstring(string s) {
        int l = 0, r = 1;
        int ret = 1;
        int n = s.size();
        int cnt = 0;
        while (r < n)
        {
            if (s[r] == s[r - 1]) cnt++;
            while (cnt > 1)
            {
                l++;
                if (s[l] == s[l - 1]) cnt--;
            }
            r++;
            ret = max(ret, r - l);
        }
        return ret;
    }
};